package demon;

import java.util.Arrays;

public class text {
    public static void main1(String[] args) {
        int[] nums ={2,2,3,3}; // 输入数组
        int val = 3; // 要移除的值
        int[] expectedNums = new int[nums.length]; // 长度正确的预期答案。
        // 它以不等于 val 的值排序。

        int k = removeElement(nums, val); // 调用你的实现

        assert k == expectedNums.length;

    }
    public static int removeElement(int[] nums, int val) {
        int count = 0;
        for(int i = 0; i < nums.length; ++i){
            if(nums[i] == val){
                count++;
            }else{
                nums[i - count] = nums[i];
            }
        }

        return nums.length - count;
    }

    public static void main(String[] args) {
        int[] nums={1,1,2};
        int k=removeDuplicates(nums);
    }
    public static int removeDuplicates(int[] nums) {


        int count=1;
        for (int i = 1; i < nums.length; i++) {
            if(nums[i-1]!=nums[i]){
                nums[count++]=nums[i];

            }
        }
        for (int i = 0; i < count; i++) {
            System.out.print(nums[i]);
        }
        return count;
    }
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int count =0;
        for (int i = m; i <m+n ; i++) {
            nums1[i]=nums2[count++];
        }
        Arrays.sort(nums1);
    }
}

